import modelExtend from 'dva-model-extend'
import { mine } from 'services/distributor'
import { lwjPageModel } from 'utils/model'
import pathToRegexp from 'path-to-regexp'

export default modelExtend(lwjPageModel, {
  namespace: 'mydistributor',
  state: {
    distributorList: []
  },
  subscriptions: {
    setup ({dispatch, history}) {
      dispatch({
        type: 'query'
      })
    },
  },
  effects: {
    *query ({}, {call, put}) {
      const {list} = yield call(mine);
      yield put({
        type: 'success',
        payload: {
          distributorList: list
        }
      });
    }
  },
  reducers: {
    success (state, {payload}) {
      return {
        ...state,
        distributorList: payload.distributorList
      }
    }
  },
})
